package com.tfswx.jcyw.ftp.config;

import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.ho.yaml.Yaml;

import java.io.File;
import java.io.FileNotFoundException;

@Data
public class Config {
    private String username;
    private String password;
    private Integer port;

    public static Config getConfig() {
        Config config;
        try {
            File configFile = new File("config/conf.yml");
            if (configFile.exists()) {
                config = Yaml.loadType(configFile, Config.class);
            } else {
                config = new Config();
            }
        } catch (FileNotFoundException e) {
            throw new RuntimeException("获取配置失败", e);
        }
        if (StringUtils.isBlank(config.getUsername())) {
            config.setUsername("tfswx");
        }
        if (StringUtils.isBlank(config.getPassword())) {
            config.setPassword("Abc12345");
        }
        if (config.getPort() == null) {
            config.setPort(2121);
        }
        return config;
    }
}
